import { useMemo } from "react";
import { useSelector } from "react-redux";
import { RootState } from "./";
export function useCar() {
  const carList = useSelector((state: RootState) => state.car.carList);

  const totalPrice = useMemo(() => {
    return carList.reduce(
      (p, n) => (n.checked ? p + n.count * +n.price : p),
      0
    );
  }, [carList]);

  return {
    totalPrice,
  };
}
